var a = require("../../requests/request.js"), t = getApp();

Page({
    data: {
        dealerInfoList: [],
        cityid: 0,
        cityname: "",
        carid: 0,
        img: "",
        carname: "",
        currentTab: 0,
        swiperTab: 0,
        carpriceimageurl: "",
        winHeight: 0,
        carparams: {},
        paramgroup: {},
        novaluegroup: {},
        dealerInfoListcount: !0,
        pricearr: []
    },
    successCallback: function(a) {
        var t = this, e = a.Data;
        console.log(a), t.data.dealerInfoList = e.List;
        for (var i in t.data.dealerInfoList) {
            var r = "4S店" === t.data.dealerInfoList[i].DealerBizModeName;
            t.data.dealerInfoList[i].Is4S = r, void 0 != t.data.dealerInfoList[i].DealerBizModeName && t.data.dealerInfoList[i].DealerBizModeName.length > 2 && (t.data.dealerInfoList[i].DealerBizModeName = t.data.dealerInfoList[i].DealerBizModeName.substring(0, 2), 
            t.data.dealerInfoList[i].DealerTel = t.data.dealerInfoList[i].DealerTel.replace(/转/, ","), 
            t.data.dealerInfoList[i].DealerTelShow = t.data.dealerInfoList[i].DealerTel.split(",")[0]);
        }
        void 0 == t.data.dealerInfoList ? (t.data.dealerInfoListcount = !1, t.data.dealerInfoList = []) : t.data.dealerInfoListcount = !0, 
        t.setData({
            cityname: t.data.cityname,
            dealerInfoList: t.data.dealerInfoList,
            dealerInfoListcount: t.data.dealerInfoListcount
        });
    },
    getCarImagUrl: function() {
        var a = this, t = "http://image.bitauto.com/bt/price/priceChart/chart/" + this.data.carid + "/0_" + this.data.carid + "_600340.png";
        a.setData({
            carpriceimageurl: "http://image.bitauto.com/wap/a/2016/10/price_default.png"
        }), wx.request({
            url: "https://wxs.app.yiche.com/checkimage.ashx?url=" + t,
            success: function(e) {
                1 === e.data && a.setData({
                    carpriceimageurl: t
                });
            }
        });
    },
    setDealerData: function() {
        var t = this;
        a.getDealerInfoList(t.data.carid, t.data.cityid, function(a) {
            t.successCallback(a);
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        });
    },
    onLoad: function(a) {
        var e = this;
        wx.getSystemInfo({
            success: function(a) {
                e.setData({
                    winHeight: a.windowHeight
                });
            }
        }), e.data.carid = a.carid, e.data.img = a.img, e.data.carname = a.showname + " " + a.carname, 
        e.data.cityid = t.globalData.locateCityInfo.id, e.data.cityname = t.globalData.locateCityInfo.name, 
        void 0 != t.globalData.selectCityParams.id && 0 != t.globalData.selectCityParams.id && "" != t.globalData.selectCityParams.id && (e.data.cityid = t.globalData.selectCityParams.id), 
        void 0 != t.globalData.selectCityParams.name && "" != t.globalData.selectCityParams.name && (e.data.cityname = t.globalData.selectCityParams.name), 
        e.getCarImagUrl(), e.setDealerData();
    },
    onShow: function() {
        var a = this;
        if (void 0 != t.globalData.selectCityParams.id && 0 != t.globalData.selectCityParams.id && "" != t.globalData.selectCityParams.id) {
            if (a.data.cityid === t.globalData.selectCityParams.id) return;
            a.data.cityid = t.globalData.selectCityParams.id;
        }
        void 0 != t.globalData.selectCityParams.name && "" != t.globalData.selectCityParams.name && (a.data.cityname = t.globalData.selectCityParams.name), 
        a.setDealerData(), a.setPriceLower();
    },
    onReady: function(a) {
        var t = this;
        wx.setNavigationBarTitle({
            title: t.data.carname
        });
    },
    onPullDownRefresh: function() {
        this.setDealerData(), this.getCarImagUrl(), wx.stopPullDownRefresh();
    },
    setPriceLower: function() {
        var t = this;
        a.getPriceLower(t.data.cityid, t.data.carid, function(a) {
            t.setData({
                pricearr: a
            });
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        });
    },
    changeCity: function() {
        var a = this;
        wx.navigateTo({
            url: "../city/city?cityid=" + a.data.cityid + "&cityname=" + a.data.cityname + "&img=" + a.data.img + "&carname=" + a.data.carname + "&carid=" + a.data.carid
        });
    },
    order: function(a) {
        var t = this;
        wx.navigateTo({
            url: "../xunjia/xunjia?carid=" + t.data.carid + "&cityid=" + t.data.cityid + "&dealerid=" + a.currentTarget.dataset.id + "&img=" + t.data.img + "&carname=" + t.data.carname + "&dealername=" + a.currentTarget.dataset.dealername + "&subordertype=0"
        });
    },
    loan: function(a) {
        var t = this;
        wx.navigateTo({
            url: "../xunjia/xunjia?carid=" + t.data.carid + "&cityid=" + t.data.cityid + "&dealerid=" + a.currentTarget.dataset.id + "&img=" + t.data.img + "&carname=" + t.data.carname + "&dealername=" + a.currentTarget.dataset.dealername + "&subordertype=2"
        });
    },
    swichNav: function(a) {
        var t = a.currentTarget.dataset.current;
        this.setData({
            currentTab: t,
            swiperTab: t
        });
    },
    swiperChange: function(a) {
        this.setData({
            currentTab: a.detail.current
        });
    },
    telDealer: function(a) {
        console.log("正在拨打电话" + a.currentTarget.dataset.tel), wx.showModal({
            title: "拨打电话",
            content: "电话号码：" + a.currentTarget.dataset.tel,
            success: function(t) {
                t.confirm && wx.makePhoneCall({
                    phoneNumber: a.currentTarget.dataset.tel
                });
            }
        });
    },
    gotoDealerLoc: function(a) {
        var t = a.currentTarget.dataset.info;
        wx.openLocation({
            latitude: t.BaiduMapLat,
            longitude: t.BaiduMapLng,
            scale: 28,
            name: t.DealerName,
            address: t.DealerSaleAddr
        });
    },
    returnBtn: function() {
        t.gotoIndex();
    }
});